﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using com.vs.General.RF;
using com.vs.General;
using com.vs.DataAccess;
using com.vs.DataAccess.DO;

namespace com.vs.RF.Web.inventory
{
    public partial class LocationInquiryEntryHandling : RFHandlingPage
    {
        private string stItem;
        private string stItemDesc;
        private string stLocation;
        private string stLPN;


        protected void Page_Load(object sender, EventArgs e)
        {
            stSourcePage = "inventory/LocationInquiryEntry.aspx";
            stTargetPage = "inventory/LocationInquiryResult.aspx";

            go();

        }

        protected override void parseRequest()
        {
            stItem = Request["tbItem"];
            stItemDesc = Request["tbItemDesc"];
            stLocation = Request["tbLoc"];
            stLPN = Request["tbLPN"];

            if (StringManager.IsEmpty(stItem) 
                && StringManager.IsEmpty(stLocation) 
                && StringManager.IsEmpty(stLPN)
                )
            {
                this.stError = MessageManager.MSG_INV_015;//必须输入至少一个查询条件;
                return;
            }
        }

        protected override void procData()
        {
            List<KeyValuePair<string, KeyValuePair<string, object>>> ltParam = null;
            //DataTable dtInv = null;
            List<LocationInventoryDO> ltInv = null;

            try
            {
                Session.Remove("INV_INQUIRY_RESULT");
                ltParam = new List<KeyValuePair<string, KeyValuePair<string, object>>>();
                if (!StringManager.IsEmpty(stItem))
                    ltParam.Add(new KeyValuePair<string,KeyValuePair<string,object>>("ITEM", new KeyValuePair<string, object>("=", stItem)));
                if (!StringManager.IsEmpty(stLocation))
                    ltParam.Add(new KeyValuePair<string, KeyValuePair<string, object>>("ITEM", new KeyValuePair<string, object>("=", stItem)));
                if (!StringManager.IsEmpty(stLPN))
                    ltParam.Add(new KeyValuePair<string, KeyValuePair<string, object>>("ITEM", new KeyValuePair<string, object>("=", stItem)));
                if (!StringManager.IsEmpty(stItemDesc))
                    ltParam.Add(new KeyValuePair<string, KeyValuePair<string, object>>("ITEM_DESC", new KeyValuePair<string, object>("LIKE", "N'%" + stItem + "%'")));


                //dtInv = LocationInventoryDO.GetTableByColumns(this.rfSess, ltParam, " ORDER BY LOCATION ");
                ltInv = LocationInventoryDO.GetListByColumns(this.rfSess, ltParam, " ORDER BY LOCATION ");
                if (ltInv == null || ltInv.Count < 1)
                {
                    this.stError = MessageManager.MSG_INV_001;//未找到库存
                    return;
                }
                Session["INV_INQUIRY_RESULT"] = ltInv;
                Session["INV_RESULT_INDEX"] = 0;
            }

            catch(Exception e)
            {
                ExceptionManager.LogException(this.rfSess, e);
                this.stError = MessageManager.MSG_GEN_000 + e.Message;
            }
        }
    }

}